package cn.virens.web.components.shiro.simple.simple;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.virens.web.components.shiro.comm.SessionUtil;

public class SimpleLogoutFilter extends LogoutFilter {
	private Logger logger = LoggerFactory.getLogger(SimpleLogoutFilter.class);

	@Override
	protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
		logger.debug("用户退出登录");

		// 获取认证令牌
		Subject subject = getSubject(request, response);
		if (subject == null) return super.preHandle(request, response);

		// 获取session管理器（不自动创建）,并清空登录缓存信息
		Session session = subject.getSession(false);
		if (session != null) SessionUtil.clearLoginInfo(session);

		return super.preHandle(request, response);
	}

}
